package JS;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class JSServer {
	public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
	    ServerSocket s = new ServerSocket(90);
	    Socket clientSocket = s.accept();
	    System.out.println("Client was accepted");
	    ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream());
	    ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream());
	    ObjectOutputStream outFile = new ObjectOutputStream(new FileOutputStream(args[0]));
	    byte[] buf = new byte[1];
	    buf[0] = 4;
	    SensorData obj;
	    do {
	        obj = (SensorData)in.readObject();
	        if (obj != null) {
	        	outFile.writeObject(obj);
	        	out.write(buf);
	        	out.flush();
	        }
	    } while (obj != null);
	    outFile.close();
	    s.close();
	}
}
